<?php
namespace Admin\Controller;
use Common\Controller\CoreController;
class OrderController extends CoreController {
	public function index(){
		$orderModel=M('order');
        $addModel=M('merchandise_order');
        if (!isset($_GET['p'])) {
        	$_GET['p']=1;
        }
		if (I('get.status')) {
			$status=I('get.status');
			$result=$orderModel->where('status=' .$status)->order('add_time desc')->page($_GET['p'].',2')->select();
			$count=$orderModel->where('status=' .$status)->count();
	            foreach ($result as $key => $value) {
	                $result[$key]['product']=$addModel->where('order_id='.$value['id'])->select();
	            }
		}else{
			$count=$orderModel->count();
			$result=$orderModel->where()->order('add_time desc')->page($_GET['p'].',2')->select();
	            foreach ($result as $key => $value) {
	                $result[$key]['product']=$addModel->where('order_id='.$value['id'])->select();
	            }
		} 
		$this->Page = new \Think\Page($count,2);
        $this->Page->setConfig('prev','上一页');
        $this->Page->setConfig('next','下一页');
        $this->assign('order',$result);
        $this->assign('index',U('index'));
		$this->display();
	}
}